package dao.review;

import java.util.List;

import util.paramvo.MemberPageListParamVO;
import util.paramvo.UnitPageListParamVO;
import util.returnvo.MajorunitReturnVO;
import vo.ReviewVO;

import com.ibatis.sqlmap.client.SqlMapClient;

public class ReviewDAOImpl implements ReviewDAO{

	private SqlMapClient sqlMapClient;

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

	@Override
	public int getReviewCount(int majorunit_no) throws Exception {
		return (Integer) sqlMapClient.queryForObject("review.getReviewCount", majorunit_no);
	}

	@Override
	public MajorunitReturnVO getAverageScore(int majorunit_no) throws Exception {
		return (MajorunitReturnVO) sqlMapClient.queryForObject("review.getAverageScore", majorunit_no);
	}

	@Override
	public ReviewVO getNewestInterestUnitReview(int member_no) throws Exception {
		return (ReviewVO) sqlMapClient.queryForObject("review.getNewestInterestUnitReview", member_no);
	}

	@Override
	public List<ReviewVO> getReviews(UnitPageListParamVO param) throws Exception {
		return sqlMapClient.queryForList("review.getReviews", param);
	}

	@Override
	public int didWriteReview(ReviewVO param) throws Exception {
		return (Integer) sqlMapClient.queryForObject("review.didWriteReview", param);
	}

	@Override
	public void registerReview(ReviewVO param) throws Exception {
		sqlMapClient.insert("review.registerReview", param);
	}

	@Override
	public void deleteReview(int review_no) throws Exception {
		sqlMapClient.update("review.deleteReview", review_no);
	}

	@Override
	public List<ReviewVO> getMyReviews(MemberPageListParamVO param) throws Exception {
		return sqlMapClient.queryForList("review.getMyReviews", param);
	}

	@Override
	public int getMyReviewCount(int member_no) throws Exception {
		return (Integer) sqlMapClient.queryForObject("review.getMyReviewCount", member_no);
	}
}
